<?php
// 本类由系统自动生成，仅供测试用途
namespace Home\Controller;
use Think\Controller;
include_once("UpFileTool1.class.php");
include_once("Common.php");
include_once("mysqlha.php");
header("Content-Type:text/html; charset=utf-8");

class TalkController extends Controller {
	
	//获取详情
	public function shaiDanDetail(){
		$talkid = $_GET["talkid"];
		$Model = M();
		$shaidanList = $Model->Query("SELECT t.title,t.addtime,t.content,t3.name,t4.luck_number,t1.fk_number,t4.quantity,t1.publictime,t2.name AS goodname FROM talk t,periods t1,goods t2,USER t3,goodsorders t4 WHERE t.id=".$talkid." AND t.fk_periods=t1.fk_number AND t3.id=t.fk_userid AND t2.id=t1.fk_goodsid AND t4.fk_userid=t.fk_userid AND t.fk_periods=t4.fk_number");
		$ImgList = $Model->Query("select pic_image from talk_images where fk_talk_id='".$talkid."'");
		for($i=0;$i<sizeof($ImgList);$i++){
			$ImgList[$i]['pic_image']="http://www.fondfell.com/superDao/".$ImgList[$i]['pic_image'];
		}
		$this->assign('images',$ImgList); 
        $this->assign("talk",$shaidanList[0]);
        $this->display("Public/page/shai_dan_xiang_qing.php");
	}
	
	//获取商品晒单
    public function getGoodSaiDan(){
          
            $goodsid = $_GET["goodsid"];			
			$userid = $_GET["userid"];

			$page = $_GET["page"];
			$pagecount = $_GET['pagecount'];
          
			if($page == null||$page<=0){
				$page=0;
			}
			  
			if($pagecount == null||$pagecount<=0){
				$pagecount=10;
			}
			
			$startcount = $page*$pagecount;
			
			$Model = M();
			
			if($goodsid == null && $userid== null){
				$SaiDanList = $Model->Query("select t.id,u.name,MIN(ti.pic_image) minimage,t.title,t.content,t.addtime from talk t,user u,talk_images ti where t.fk_userid=u.id and t.id =ti.fk_talk_id group by u.name,t.title,t.content,t.addtime limit ".$startcount.",".$pagecount."");
			}
			else if($goodsid != null && $userid== null){
				$SaiDanList = $Model->Query("select t.id,u.name,MIN(ti.pic_image) minimage,t.title,t.content,t.addtime from talk t,user u,talk_images ti where t.fk_userid=u.id and t.id =ti.fk_talk_id and t.fk_goodsid ='".$goodsid."' group by u.name,t.title,t.content,t.addtime limit ".$startcount.",".$pagecount."");
			}
			else{
				$SaiDanList = $Model->Query("select t.id,u.name,MIN(ti.pic_image) minimage,t.title,t.content,t.addtime from talk t,user u,talk_images ti where t.fk_userid=u.id and t.id =ti.fk_talk_id and u.id ='".$userid."' group by u.name,t.title,t.content,t.addtime limit ".$startcount.",".$pagecount."");
			}
		 
			 echo getSuccessJson($SaiDanList);
    }

	//添加评论
    public function addReply(){
		$userid = $_GET['userid'];
		$content = $_GET['content'];
		$goodsid = $_GET['goodsid'];
		if ($_FILES) {

			$UpFileTool = new \Think\UpFileTool('file');// 实例化上传类
			$UpFileTool->multiImage(100, 100 ,'sumbimage', $srcimage='srcimage');
			$multiSumbImage = $UpFileTool->multiSumbImage;
			$multiSrcImage = $UpFileTool->multiSrcImage;
			$insertArr = array(
			   "content"=>$content,
				"fk_userid"=>$userid,
				"fk_goodsid"=>$goodsid,
				"images"=>$multiSrcImage,
				"simpleimg"=>$multiSumbImage
			);
            myinsert('talk',$insertArr);
			$resultArr = array(
			   "code"=>200,
				"msg"=>"添加成功"
			);
			echo json_encode($resultArr);
		}
	}
}